package com.av.bcacc.jetpack.viewmodel;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;
import android.view.View;

import com.av.bcacc.jetpack.R;
import com.av.bcacc.jetpack.databinding.ActivityScreenOrientationBinding;
import com.av.bcacc.jetpack.modle.viewmodel.CounterModel;
/**
 * @description viewModle的使用
 * @author weiliang hu
 * @time 2021/5/12 23:06
 * @email:2072025612@qq.com
 */

public class ViewModelActivity extends AppCompatActivity {

    ActivityScreenOrientationBinding orientationBinding;
    private CounterModel counterModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        orientationBinding= DataBindingUtil.setContentView(this, R.layout.activity_screen_orientation);
        counterModel= new ViewModelProvider(this).get(CounterModel.class);
        counterModel.getCurrentCounter().observe(this, new Observer<Integer>() {
            @Override
            public void onChanged(Integer integer) {
                orientationBinding.textView4.setText(String.valueOf(integer));
            }
        });
        orientationBinding.button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                counterModel.addCurrenCounter(1);
            }
        });
    }
}
